﻿/********************************************************************************
** 作者： 吴汉阳
** 创建时间： 2009-10-12
** 描述：
** 绑定角色树-涉及到的相关方法
********************************************************************************/

Ext.InfoLoader = Ext.extend(Ext.tree.TreeLoader,
         { 
            tempvalue : null,
            createNode : function(attr){
            // apply baseAttrs, nice idea Corey!
	        if(this.tempvalue != null && this.tempvalue != "") {
	            var tempArray = this.tempvalue.split(",");
	            Ext.each(tempArray,function(n){
		            if(attr["id"] == n) {
		            
			            attr["checked"] = true;
		            }
	            },this);
	        }
                if(this.baseAttrs){
                    Ext.applyIf(attr, this.baseAttrs);
                }
                if(this.applyLoader !== false){
                    attr.loader = this;
                }
                if(typeof attr.uiProvider == 'string'){
                   attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
                }
                if(attr.nodeType){
                    return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
                }else{
                    return attr.leaf ?
                                new Ext.tree.TreeNode(attr) :
                                new Ext.tree.AsyncTreeNode(attr);
                }
            }
    });


    function ShowRoleWin(BindValue,UserID,strTitle)
     {
         var rootNodeTrade={nodeType: 'async',text:'所有角色',draggable:false,id:'TreeRoleAll',collapsed:false,expanded:true};
         // 定义树对象
         var TradeTree = new Ext.tree.TreePanel(
         {
              columnWidth:1,
              id : 'treeRoleTrade',
              margins : '2 2 0 2',
              autoScroll : true,
              root : rootNodeTrade,
              height : 209,
              width : 203,
              singleExpand : false,
              checkModel :"childCascade",  // 对树的级联多选
              onlyLeafCheckable : false,   // 对树所有结点都可选
              loader : new Ext.InfoLoader(
              {
                  dataUrl: strPath + 'SystemManage/GetRoleTree.aspx',
                 tempvalue: BindValue,
                 baseAttrs :
                 {
                    uiProvider : Ext.ux.TreeCheckNodeUI
                 }
              }
             )
         }
        );
        
        winHbDepartMent = new Ext.Window({
        title: '&nbsp;'+strTitle,
        width: 420,
        height:450,
        layout:'fit',
        plain:true,
        closeAction :'hide',
        modal:true,
        deferredRender:false,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items:TradeTree,
        buttons: [{
                text: '确定',
                id:'btnTreeRoleInfo',
                name:'btnTreeRoleInfo',
                handler:function(){
                    var checkText = new Array;
                    var checkId = new Array;
                    var len = TradeTree.getChecked();
                    for (var i = 0; i < len.length; i++) 
                    {
                        if(len[i].getDepth()<1) continue;
                        checkId.push(len[i].id);
                    }
                    var RoleIDs = checkId.toString();
                    UpdateOrganRole(UserID,RoleIDs);
                    winHbDepartMent.close();
                  }
                },{
                text: '关闭',
                handler:function(){
                     winHbDepartMent.close();
                 }
            }]
       });
       winHbDepartMent.show();
       TradeTree.expandAll();
  }